package com.whfc.iot.fse.crane.processor;

import com.alibaba.fastjson.JSONObject;
import com.whfc.common.constant.QueueConst;
import com.whfc.common.enums.DevicePlatform;
import com.whfc.common.util.JSONUtil;
import com.whfc.fse.dto.FseCraneParamDTO;
import com.whfc.iot.fse.crane.entity.TwMsg;
import com.whfc.iot.fse.crane.entity.TwMsgParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 塔吊消息处理-设置参数
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/7/17 9:17
 */
@Component
public class TwUpMsgProcessorParam implements TwUpMsgProcessor<TwMsgParam> {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Override
    public void processMsg(TwMsgParam twMsgParam) {
        logger.info("处理塔吊设置参数消息:{}", JSONUtil.toString(twMsgParam));
        try {
            if (twMsgParam == null) {
                return;
            }

            FseCraneParamDTO fseCraneParamDTO = new FseCraneParamDTO();
            fseCraneParamDTO.setSn(twMsgParam.getDeviceSn()+"");
            fseCraneParamDTO.setPlatform(DevicePlatform.whfciot.name());
            fseCraneParamDTO.setRearArmLength(twMsgParam.getPhbc());
            fseCraneParamDTO.setForeArmLength(twMsgParam.getQzbc());
            fseCraneParamDTO.setMaxWeight(twMsgParam.getMaxWeight());
            fseCraneParamDTO.setTowerArmHeight(twMsgParam.getTsgd());
            fseCraneParamDTO.setMaxMomentRatio(twMsgParam.getMaxMomentRatio());
            amqpTemplate.convertAndSend(QueueConst.FSE_CRANE_PARAM_DATA, JSONUtil.toString(fseCraneParamDTO));
        } catch (Exception ex) {
            logger.error("", ex);
        }
    }
}
